Calculate the difference between the squared sumsΒΆ
Calculate the difference between:
the squared sum of first N natural numbers and
the sum of squared first N natural numbers.
(default value of number = 2).
Test Data:
sum_difference(12)
Expected output:
5434
def sum_difference(n=2):
sum_of_squares = 0
square_of_sum = 0
for num in range(1, n + 1):
sum_of_squares += num * num
square_of_sum += num
square_of_sum = square_of_sum ** 2
return square_of_sum - sum_of_squares
# test
print(sum_difference(12))
Output:
5434